
class TreeUtil:
    
    @staticmethod
    def build_tree_nodes(treeNodes, pk:str='id', pid:str="pid"):
        nodeDict = {}
        for node in treeNodes:
            node['children'] = []
            nodeDict[node[pk]] = node

        for node in treeNodes:
            if node[pid] != 0:
                nodeDict[node[pid]]['children'].append(node)

        result = []

        for node in treeNodes:
            if node[pid] == 0:
                result.append(node)

        return result